import java.util.LinkedList;

public class Block {
	LinkedList<Invariant> listInv;
//	LinkedList<Instruction> listInstr;
	LinkedList<Affectation> listAff;
	
	public Block(String s, EnsembleVariable ev){
		//block = inv \n instr \n ... instr \n inv \n @
		listInv = new LinkedList<Invariant>();
//		listInstr = new LinkedList<Instruction>();
		listAff = new LinkedList<Affectation>();
		
//		int lengthStr = s.length();
		String ms = s;
		int i=-1; 
		int carLu;
		StringBuffer buffer = new StringBuffer();
		
		
		i++;
		carLu = s.charAt(i);
		
		//lire le premier inv
		do{
			carLu= s.charAt(i);
			buffer.append((char)carLu);
			i++; 
		}while("\n".indexOf(s.charAt(i))==-1);
		ms = buffer.toString();
		buffer.delete(0,buffer.length());	
		listInv.add(new Invariant(ms,ev));

		//now i=\n
		i++;//
		if(s.charAt(i)==(int)'@') return;
		//lire le premir instr
		do{
			carLu= s.charAt(i);
			buffer.append((char)carLu);
			i++; 
		}while("\n".indexOf(s.charAt(i))==-1);
		ms = buffer.toString();
		buffer.delete(0,buffer.length());
		listAff.add(new Affectation(ms,ev));
		
		i++;
		ms = s.substring(i);
		listInv.addAll(new Block(ms,ev).listInv);
		listAff.addAll(new Block(ms,ev).listAff);
	}
	
	public void publish(EnsembleVariable ev){
		int l = listAff.size();
		for(int j = 0; j<l;j++){
			listInv.get(j).publish(ev);
			listAff.get(j).publish(ev);System.out.println();
		}
		listInv.get(l).publish(ev);
	}
}
